import 'dart:core';

extension ListDeduplicationExtension<E> on List<E> {
  /// 数据去重
  ///
  /// [compare] 去重条件判断式
  List<E> deduplication(bool compare(E a, E b)) {
    List<E> resultList = List();
    for (var i = 0; i < this.length; i++) {
      if (this[i] != null) {
        var flag = true;
        for (var j = 0; j < resultList.length; j++) {
          if (compare(this[i], resultList[j])) {
            flag = false;
            break;
          }
        }
        if (flag) {
          resultList.add(this[i]);
        }
      }
    }
    return resultList;
  }
}
